
<!--  预算科目-->
<template>
  <a-card :bordered="false">
    <!-- 查询区域 -->
    <search ref="search"  :config="searchConfig" @search="search" @getHeight="getHeight"/>

    <!-- table区域-begin -->
    <div class='page_table'>
      <vxe-grid
        ref='xGrid'
        v-bind='vexConfig'
        :align='left'
        :border='true'
        :checkbox-config='checkboxConfig'
        :columns='columns'
        :data='dataSource'
        :height='pageHeight-seachHeight-94'
        :loading='loading'
        :resizable='true'
        :showOverflow='true'
        :toolbar-config='tableToolbar'
        size='mini'
        @checkbox-change='selectChangeEvent'
        @checkbox-all='selectChangeEvent'
      >
        <template #toolbar_buttons>
          <!-- 操作按钮区域 -->
          <div class='table-operator'>
            <a-button type="primary" @click="handleAddStore">新增</a-button>
            <a-button type="primary" @click='batchDel'>删除</a-button>
            <a-button type="primary" @click="stateChange(1)">启用</a-button>
            <a-button type="primary" @click="stateChange(0)">禁用</a-button>
            <a-button type="primary" @click="handleExportXls('预算科目')">模板下载</a-button>
            <a-upload
              :action="importExcelUrl"
              :headers="tokenHeader1"
              :multiple="false"
              :showUploadList="false"
              name="file"
              @change="handleImportExcel"
            >
              <a-button type="primary">导入</a-button>
            </a-upload>
            <a-button type='primary' @click="downExportXls('tpmBudgetSubjects_service')">导出</a-button>
          </div>
        </template>
        <template #detail='{ row,rowIndex }'>
          <a @click="handleAddStore(row,'查看')">{{ row.subjectsCode }}</a>
        </template>
        <template #status='{ row }'>
          <a-switch :checked="row.status" size="small" @change="handleStatus(row,$event)"/>
        </template>

        <template #pager>
          <vxe-pager
            :currentPage.sync='ipagination.current'
            :layouts="['Total', 'PrevJump', 'PrevPage', 'Number', 'NextPage', 'NextJump','Sizes', 'FullJump']"
            :page-size.sync='ipagination.pageSize'
            :pageSizes='ipagination.pageSizeOptions'
            :total='ipagination.total'
            @page-change='handlePageChange'>
          </vxe-pager>
        </template>
      </vxe-grid>
    </div>
    <!-- table区域-end -->

    <form-add-edit ref="popupForm"  @ok="modalFormOk"></form-add-edit>
    <business-log ref="businessLog"></business-log>
  </a-card>
</template>

<script>
import { PageListMixin } from '@/mixins/PageListMixin'
import { getAction, postAction } from '@api/manage'
import formAddEdit from '@comp/view/base-crud/form/FormAddEdit'
import Vue from 'vue'
import { ACCESS_TOKEN, TENANT_ID } from "@/store/mutation-types"
import JEllipsis from "@/components/cn-form/JEllipsis";
export default {
  name: 'budgetItems',
  mixins:[PageListMixin],
  components: {
   formAddEdit,JEllipsis
  },
  data () {
    return {
      tokenHeader1: {'loginUserToken':  Vue.ls.get(ACCESS_TOKEN)},
      description: '预算科目',
      searchConfig:[
        {
          type:'input',
          name:'subjectsCode',
          placeholder:'预算科目编号',
        },{
          type:'input',
          name:'subjectsName',
          placeholder:'预算科目名称',
        },{
          type:'a-select',
          name:'carryType',
          option:[{
            name:'不转结',
            value:1
          },{
            name:'按月转结',
            value:2
          },{
            name:'年度费用',
            value:3
          }],
          placeholder:'结转方式',
        },{
          type: 'j-select',
          dictCode:'tpm_subjects_group',
          placeholder: '预算科目分组',
          name: 'subjectsGroup',  // 后台接受字段
        },
        {
          type: 'a-select',
          name: 'status',
          placeholder: '状态',
          option: [
            {
              name: '启用',
              value: 1
            },
            {
              name: '停用',
              value: 0
            }]
        }],
      // 表头
      columns: [
        { type: 'checkbox', width: 50, fixed: null ,field: 'a',},
        {
          title: '预算科目编号',
          field: 'subjectsCode',
          minWidth: 120,
          slots: {default: 'detail'}
        },
        {
          title: '预算科目名称',
          field: 'subjectsName',
          minWidth: 120,
        },

        {
          title: '结转方式',
          minWidth: 100,
          field: 'carryTypeStr',
        },
        {
          title: '预算科目分组',
          minWidth: 120,
          field: 'subjectsGroupStr',
        },
        {
          title: '备注',
          minWidth: 80,
          field: 'remarks',

        },
        {
          title: '创建人',
          minWidth: 80,
          field: 'createName',

        },
        {
          title: '创建时间',
          minWidth: 120,
          field: 'createTime',
        },
        {
          title: '更新人',
          width: 80,
          field: 'updateName',

        },
        {
          title: '更新时间',
          width: 120,
          field: 'updateTime',
        },
        {
          title: '状态',
          field: 'status',
          width: 80,
          fixed:'right',
          slots: { default: 'status' },
        },
      ],

      url: {
        // 列表接口
        list: window._CONFIG['domianTpmURL']+ "/budget/tpmBudgetSubjects/findPageList",
        // 详情接口
        // detail: window._CONFIG['domianKaURL']+ "/kaOrder/getInfo",
        // 导出接口
        // exportXlsUrl: window._CONFIG['domianTpmURL']+"budget/tpmBudgetFee/exportXls",
        // 删除接口
        deleteBatch:window._CONFIG['domianTpmURL']+ "/budget/tpmBudgetSubjects/deleteBatch",
        // 启停用接口
        status:window._CONFIG['domianTpmURL']+ "/budget/tpmBudgetSubjects/startOrStop",
        startOrStopUrl:window._CONFIG['domianTpmURL']+ "/budget/tpmBudgetSubjects/startOrStop",
        importExcelUrl: window._CONFIG['domianTpmURL'] + "/budget/tpmBudgetSubjects/importExcel",
        exportXlsUrl: window._CONFIG['domianTpmURL'] + "/budget/tpmBudgetSubjects/exportXls",
      }
    }
  },
  created() {


  },

  watch:{

  },

  computed: {

  },
  methods: {
    importExcelUrl: function() {
      return `${this.url.importExcelUrl}`;
    },
    handleAddStore(record,title,disabled=false) {
      let config = {
        title: title||'新增',
        width: 600,
        disableSubmit:title=='查看'?true:false,
        addOrUpdateUrl: `${window._CONFIG['domianTpmURL']}/budget/tpmBudgetSubjects/saveOrUpdate`,  //审核地址
        method: 'post',
        disabled:disabled,
        list: [
          {
            label: '预算科目编号',
            type: 'input',
            placeholder: '预算科目编号',
            disabled:title=='查看'?true:false,
            name: 'subjectsCode',  // 后台接受字段
            check: { rules: [{ required: true, message: '预算科目编号' }] },
          },
          {
            label: '预算科目名称',
            type: 'input',
            disabled:title=='查看'?true:false,
            placeholder: '预算科目名称',
            name: 'subjectsName',  // 后台接受字段
            check: { rules: [{ required: true, message: '预算科目名称' }] },
          },
          {
            label: '预算科目分组',
            type: 'j-select',
            disabled:title=='查看'?true:false,
            dictCode:'tpm_subjects_group',
            placeholder: '请选择预算科目分组',
            name: 'subjectsGroup',  // 后台接受字段
            check: { rules: [{ required: true, message: '请选择预算科目分组' }] },
          },
          {
            label: '结转方式',
            type: 'a-select',
            disabled:title=='查看'?true:false,
            placeholder: '请选择结转方式',
            name: 'carryType',  // 后台接受字段
            check: { rules: [{ required: true, message: '请选择结转方式' }] },
            option:[{
              name:'不转结',
              value:1
            },{
              name:'按月转结',
              value:2
            },{
              name:'年度费用',
              value:3
            }],
          },
          {
            label: '是否控制',
            type: 'a-select',
            disabled:title=='查看'?true:false,
            placeholder: '是否控制',
            name: 'isControl',
            check: { rules: [{ required: true, message: '是否控制' }] },
            option:[{
              name:'控制',
              value:1
            },{
              name:'不控制',
              value:0
            }],
          },
          {
            label: '备注',
            type: 'textarea',
            disabled:title=='查看'?true:false,
            placeholder: '请输入备注',
            name: 'remarks',  // 后台接受字段
            // check: { rules: [{ required: true, message: '请选择月度' }] },
          },

        ]
      }
      this.$refs.popupForm.edit(record,config )
      this.$refs.popupForm.disableSubmit = false
    },

    handlePageChange(page,pageSize){
      this.ipagination.current=page
      this.loadData()
    },
    handleSizeChange(current,size){
      this.ipagination.pageSize=size
      this.loadData()
    },
  }
}
</script>

<style lang="less" scoped>
@import '~@assets/less/common.less';
/deep/ .ant-pagination{
  float:right;
}

///deep/ .resize-table-th {
//  position: relative;
//}
///deep/ .table-draggable-handle {
//  height: 100% !important;
//  bottom: 0;
//  left: auto !important;
//  right: -5px;
//  cursor: col-resize;
//  touch-action: none;
//}

</style>